// component/pickerColumnView/pickerColumnView.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    list: {
      type: Array,
      value: [[100, 200, 300], ['-'], [100, 200, 300]]
    },
    title: {
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    pickerList: [],
    startValue: null,
    endValue: null,
    startIndex: 0,
    endIndex: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    cancelEvent() {
      this.triggerEvent("change", {
        cancel: true,
        confirm: false
      })
    },
    confirmEvent() {
      const { pickerList, startIndex, endIndex } = this.data
      const list = JSON.parse(JSON.stringify(this.data.list));
      const [startArr, endArr] = [list.shift(), list.pop()];
      const [startValue, endValue] = [startArr[startIndex], endArr[endIndex]]
      this.triggerEvent("change", {
        startValue, endValue, startIndex, endIndex,
        list: pickerList,
        value: [startValue, endValue],
        valueAll: [startValue, '-', endValue],
        valueIndex: [startIndex, endIndex],
        confirm: true,
        cancel: false,
      })
    },
    pickerChange(event) {
      const list = JSON.parse(JSON.stringify(this.data.list));
      const listIndex = event.detail.value;
      const [startArr, endArr] = [list.shift(), list.pop()];
      const [startIndex, endIndex] = [listIndex.shift(), listIndex.pop()];
      const [startValue, endValue] = [startArr[startIndex], endArr[endIndex]]
      const newEndArr = endArr.filter(item => parseInt(item) >= parseInt(startValue))
      const pickerList = [startArr, ['-'], newEndArr]
      this.setData({ pickerList, startValue, endValue, startIndex })
    },
    infoEvent() {
      this.setData({ pickerList: this.data.list })
    },
  },
  /**
   * 生命周期
   * 在组件实例进入页面节点树时执行
   */
  lifetimes: {
    attached: function () {
      this.infoEvent()
    }
  }
})
